/*
 * Expression.cpp
 *
 *  Created on: 24 nov. 2013
 *      Author: baker
 */

#include "Expression.h"


Expression::Expression(Term* right, Term* left, enum Operateur op) {
	this->_right = right;
	this->_left = left;
	this->_op = op;
}

Expression::Expression(Term* term) {
	this->_right = term;
	this->_left = term;
	this->_op = Operateur::Nothing;
}

Operateur Expression::get_operateur() {
	return this->_op;
}

Term* Expression::get_right() {
	return this->_right;
}
Term* Expression::get_left() {
	return this->_left;
}

float Expression::result(){
	if(this->_op == Operateur::Nothing)
	{
		return this->_left->result();
	}
	else
	{
		float resR = this->_right.result();
		float resL = this->_left->result();
		if(this->_op == Operateur::Plus){
			return resR + resL;
		}
		if(this->_op == Operateur::Minus){
			return resR - resL;
		}
		if(this->_op == Operateur::Div){
			return (resR / resL);
		}
		if(this->_op == Operateur::Mult){
			return (resR * resL);
		}
	}
	return 0;
}

Expression::~Expression() {
	delete this->_left;
	delete this->_right;
	delete this->_op;
}


